<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="View.*" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<% ItemView item = (ItemView) request.getAttribute("item"); %>
<title><%if(item != null) {%><%=item.getName() %><%}else{%>ToWa Webshop<%}%></title>
<script type="text/javascript">
function validate(){
 var nr = document.itemForm.amount.value;
 if(isNaN(nr)){
  alert("The amount is not a number");
  return false;
 }
 if(nr < 1){
  alert("Amount is less than one");
  return false;
 }
 return true;
}
</script>
</head>

<body>
<div id="container">
	<jsp:include page="header.jsp" />
	<jsp:include page="menu.jsp" />
	<div id="content">	
		<%if(item == null){ %>
			<h1>There is no item with id <%=request.getParameter("id") %></h1>
		<%}else{ %>
			<form name="itemForm" action="item" method="post" onsubmit="return validate()">
				<table>
					<tr>
						<td><h1><%=item.getName() %></h1></td>
					</tr>
					<tr>
						<td><b>Category:</b></td><td><%=request.getAttribute("category") %></td>
					</tr>
					<tr>
						<td><b>In Stock:</b></td>
						<td><%=item.getAmount() %></td>
					</tr>
					<tr>
						<td><b>Price:</b></td>
						<td><%=item.getPrice() %> SEK</td>
					</tr>
					<tr>
						<td><input type="submit" value="Place in cart"> <input type="text" name="amount" size="1" value="1"/></td>
					</tr>
				</table>
				<hr />
				<table>
					<tr>
						<td><b>Description</b></td>
					</tr>
					<tr>
						<td><%=item.getDescription().replaceAll("\n", "<br/>") %></td>
					</tr>
				</table>
				<input type="hidden" name="hidden" value="addToCart" />
				<input type="hidden" name="id" value="<%=request.getParameter("id") %>" />
			</form>
		<%} %>
		</div>
		<jsp:include page="shoppingcart.jsp" />
		<jsp:include page="footer.jsp" />
	</div>
</body>
</html>